home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWEvents / FWEventU.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  4.2 KB  |  184 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWEventU.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWEVENTU_H
  13. #include "FWEventU.h"
  14. #endif
  15.  
  16. #ifndef FWGC_H
  17. #include "FWGC.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWACQUIR_H
  25. #include "FWAcquir.h"
  26. #endif
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWPART_H
  33. #include "FWPart.h"
  34. #endif
  35.  
  36. #ifndef FWSESION_H
  37. #include "FWSesion.h"
  38. #endif
  39.  
  40. #ifndef SLMIXOS_H
  41. #include "SLMixOS.h"
  42. #endif
  43.  
  44. #ifndef FWSOMENV_H
  45. #include "FWSOMEnv.h"
  46. #endif
  47.  
  48. #ifndef SOM_ODWindow_xh
  49. #include <Window.xh>
  50. #endif
  51.  
  52. #ifndef SOM_ODFacet_xh
  53. #include <Facet.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODDispatcher_xh
  57. #include <Disptch.xh>
  58. #endif
  59.  
  60. #if defined(FW_BUILD_MAC) && !defined(__EVENTS__)
  61. #include <Events.h>
  62. #endif
  63.  
  64. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  65. #include <windows.h>
  66. #endif
  67.  
  68. #pragma segment fwevents
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // ::FW_IsKeyPressed
  72. //----------------------------------------------------------------------------------------
  73.  
  74. FW_Boolean FW_IsKeyPressed(unsigned short theKey)
  75. {
  76. #ifdef FW_BUILD_MAC
  77.     KeyMap theKeyMap;
  78.     ::GetKeys(theKeyMap);
  79.     const unsigned char *theKeys = (const unsigned char *) theKeyMap;
  80.     return ((theKeys[theKey >> 3] >> (theKey & 7)) & 1);
  81. #endif
  82.  
  83. #ifdef FW_BUILD_WIN
  84.     return ((::GetKeyState(theKey) & 0x8000) != 0);
  85. #endif
  86. }
  87.  
  88. //----------------------------------------------------------------------------------------
  89. // ::FW_GetMouseLocation
  90. //----------------------------------------------------------------------------------------
  91. //    return value in frame coordinate
  92.  
  93. FW_CPoint FW_GetMouseLocation(Environment* ev, ODFacet* facet)
  94. {
  95.     FW_CPlatformPoint windowLoc;
  96.     
  97.     ODWindow* window = facet->GetWindow(ev);
  98.     ODPlatformWindow plfmWindow = window->GetPlatformWindow(ev);
  99.     
  100. #ifdef FW_BUILD_MAC
  101.     GrafPtr curPort;
  102.     ::GetPort(&curPort);
  103.     ::SetPort(plfmWindow);
  104.     ::GetMouse(&windowLoc);
  105.     ::SetPort(curPort);
  106. #endif
  107.  
  108. #ifdef FW_BUILD_WIN
  109.     ::GetCursorPos(&windowLoc);
  110.     ::ScreenToClient(plfmWindow, &windowLoc); 
  111. #endif
  112.  
  113.     FW_CPoint point(windowLoc);
  114.     FW_WindowToFrame(ev, facet, point);
  115.  
  116.     return point;
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. // ::FW_GetMouseLocation
  121. //----------------------------------------------------------------------------------------
  122. //    return value in content coordinate
  123.  
  124. FW_CPoint FW_GetMouseLocation(ODWindow* theODWindow, FW_CGraphicContext& theGC)
  125. {
  126.     FW_CPlatformPoint plformLoc;
  127.     
  128. #ifdef FW_BUILD_MAC
  129.     FW_UNUSED(theODWindow);
  130.     ::GetMouse(&plformLoc);
  131. #endif
  132.  
  133. #ifdef FW_BUILD_WIN
  134.     FW_SOMEnvironment ev;
  135.     ::GetCursorPos(&plformLoc);
  136.     ODPlatformWindow plfmWindow = theODWindow->GetPlatformWindow(ev);
  137.     ::ScreenToClient(plfmWindow, &plformLoc); 
  138. #endif
  139.  
  140.     return theGC.DeviceToLogical(plformLoc);
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. // ::FW_WaitMouseUp
  145. //----------------------------------------------------------------------------------------
  146.  
  147. FW_Boolean FW_WaitMouseUp()
  148. {
  149. #ifdef FW_BUILD_MAC
  150.     return ::StillDown(); //::WaitMouseUp();
  151. #endif
  152. #ifdef FW_BUILD_WIN
  153.     MSG event;
  154.     if (::PeekMessage(&event, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE))
  155.     {
  156.         return event.message != WM_LBUTTONUP && 
  157.                 event.message != WM_RBUTTONUP &&
  158.                  event.message != WM_LBUTTONDOWN &&
  159.                 event.message != WM_RBUTTONDOWN;
  160.     }
  161.     return TRUE;
  162. #endif
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. // ::FW_WaitFor
  167. //----------------------------------------------------------------------------------------
  168.  
  169. void FW_WaitFor(long tickCount)
  170. {
  171.     long targetTick = ::FW_GetTickCount() + tickCount;
  172.     while (::FW_GetTickCount() <= targetTick) {}
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. // ::FW_ForceAdjustCursor
  177. //----------------------------------------------------------------------------------------
  178.  
  179. void FW_ForceAdjustCursor(Environment *ev)
  180. {
  181.     FW_CSession::GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  182. }
  183.  
  184.